package com.two.medbooking.controller;

import com.two.medbooking.entity.Department;
import com.two.medbooking.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/department")
public class DepartmentController {

    @Autowired
    private DepartmentService departmentService;

    @GetMapping
    public List<Department> departmentList() {
        return departmentService.ListAllDepartment();
    }

    @PostMapping("/updateStatus")
    public boolean updateDepartment(@RequestBody Department department) {
        return departmentService.updateById(department);
    }

    @DeleteMapping("/{depId}")
    public boolean deleteDepartment(@PathVariable Integer depId) {
        return departmentService.removeById(depId);
    }

    @PostMapping
    public boolean addDepartment(@RequestBody Department department) {
        return departmentService.save(department);
    }

    @PutMapping("/{depId}")
    public boolean updateDepartment(@PathVariable Integer depId, @RequestBody Department department) {
        department.setDepId(depId);
        return departmentService.updateById(department);
    }

    // 如果需要分页功能添加以下方法
    /*
    @GetMapping("/page")
    public Page<Department> getDepartmentByPage(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        return departmentService.page(new Page<>(pageNum, pageSize));
    }
    */
}